package top.ajun.mall.ware.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import top.ajun.common.utils.PageUtils;
import top.ajun.common.utils.Query;
import top.ajun.mall.ware.dao.WareInfoDao;
import top.ajun.mall.ware.entity.WareInfoEntity;
import top.ajun.mall.ware.service.WareInfoService;

import java.util.Map;

@Service("wareInfoService")
public class WareInfoServiceImpl extends ServiceImpl<WareInfoDao, WareInfoEntity> implements WareInfoService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<WareInfoEntity> page = this.page(
            new Query<WareInfoEntity>().getPage(params),
            Wrappers.query()
        );
        return new PageUtils(page);
    }

    @Override
    public PageUtils queryPageByCondition(Map<String, Object> params) {
        LambdaQueryWrapper<WareInfoEntity> wrapper = Wrappers.lambdaQuery();

        // 检索条件
        String key = (String) params.get("key");
        if (StrUtil.isNotEmpty(key)) {
            wrapper
                .eq(WareInfoEntity::getId, key).or()
                .like(WareInfoEntity::getName, key).or()
                .like(WareInfoEntity::getAddress, key).or()
                .like(WareInfoEntity::getAreacode, key);
        }

        IPage<WareInfoEntity> page = this.page(new Query<WareInfoEntity>().getPage(params), wrapper);
        return new PageUtils(page);
    }

}